package com.atguigu.scala.chapter6

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.serializer.SerializeFilter

import scala.beans.BeanProperty

/**
 * @author lizikuan
 * @date 2021/5/21 20:05
 */
object $03_ClassConstruct {
  class Student{
    @BeanProperty
    var name:String=_

    @BeanProperty
    var age:Int = 18
  }


  class Person(private var name : String="zhangsan",var age : Int = 20,address : String ="zhongguo"){
    def this(name:String){
      this(name,20,"123")
    }

    def this(name:String,address:String){
      this(name)
    }

    def getName() = name

  }

  def main(args: Array[String]): Unit = {
    val student = new Student
    student.setName("niezong")
    println(student.getName)
    println(student.getAge)

    val person = println(new Person("zzzzz").getName())
    println(new Person("lisi", "diqiu").getName())

    //对象转json
    val str = JSON.toJSONString(student, null.asInstanceOf[Array[SerializeFilter]])
    println(str)
    //json转对象
    val student1 = JSON.parseObject(str, classOf[Student])
    println(student1.getName)
  }
}
